//user.js
//获取应用实例
const app = getApp()
Page({
  data: {
    result: '',
    data: '',
    showModal: false,
    nickName: '',
    avatarUrl: '',
    gender: '',
    userInfo: '',
    hasUserInfo: false,
    inputval1:'',
    inputval2:'',
    TextAreaval:'',
    user_id: ''

  },
  // 商务合作事件弹窗start
  inputChange1:function(e){
    var inputval1 = e.detail.value;
    this.setData({
      inputval1: inputval1
    })
  },
  inputChange2: function (e) {
    var inputval2 = e.detail.value;
    this.setData({
      inputval2: inputval2
    })
  },
  bindTextArea: function (e) {
    var TextAreaval = e.detail.value;
    this.setData({
      TextAreaval: TextAreaval
    })
  },
  showDialogBtn: function () {
    this.setData({
      showModal: true
    })
  },
  /**
   * 弹出框蒙层截断touchmove事件
   */
  preventTouchMove: function () {
    
  },
  /**
   * 隐藏模态对话框
   */
  hideModal: function () {
    this.setData({
      showModal: false
    });
  },
  /**
   * 对话框取消按钮点击事件
   */
  onCancel: function () {
    this.hideModal();
  },
  /**
   * 对话框确认按钮点击事件
   */
  onConfirm: function () {
    var that = this;
    wx.getStorage({
      key: 'user_id',
      success: function (res) {
        that.setData({
          user_id: res.data
        })
      }
    })
    wx.getStorage({
      key: 'avatarUrl',
      success: function (res) {
        that.setData({
          avatarUrl: res.data
        })
      }
    })
    wx.getStorage({
      key: 'gender',
      success: function (res) {
        that.setData({
          gender: res.data
        })
      }
    })
    wx.getStorage({
      key: 'nickName',
      success: function (res) {
        console.log(res.data);
        that.setData({
          nickName: res.data
        })
      }
    })
    var inputval1 = that.data.inputval1;
    var inputval2 = that.data.inputval2;
    var TextAreaval = that.data.TextAreaval;
    if (inputval1 != '' && inputval2 != '' && TextAreaval !=''){
          wx.request({
            url: 'https://www.cacalife.cn/home/lecaca/shophezuos',
            methods: 'POST',
            data: {
              'avatarUrl': that.data.avatarUrl,
              'gender': that.data.gender,
              'nickName': that.data.nickName,
              'user_id': that.data.user_id,
              'name': inputval1,
              'mobile': inputval2,
              'desc': TextAreaval
            },
            header: { 'content-type': 'application/json' },
            success: function (res) {
              console.log(res);
              if(res.data==1){
                wx.showToast({
                  title: '成功',
                  icon: 'succes',
                  duration: 1000,
                  mask: true
                })
              }else{
                wx.showModal({
                  title: '提示',
                  content: '提交失败，请重新填写',
                  success: function (res) {
                    if (res.confirm) {
                      console.log('用户点击确定')
                    }
                  }
                })
              }
            },
            fail: function (res) {
              console.log(res)
            }
          })
    }else{

    }

    this.hideModal();
  },
 // 商务合作事件弹窗end
  
})
